package com.chandra.pos.order.dao.entity;

import org.primefaces.model.SelectableDataModel;

import javax.faces.model.ListDataModel;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Customer: Admin
 * Date: 10/8/13
 * Time: 12:49 AM
 * To change this template use File | Settings | File Templates.
 */
public class OrderItemDataModel extends ListDataModel<OrderItem> implements SelectableDataModel<OrderItem> {

    public OrderItemDataModel() {
    }

    public OrderItemDataModel(List<OrderItem> data) {
        super(data);
    }

    @Override
    public Object getRowKey(OrderItem object) {
        return object.getProduct().getId();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public OrderItem getRowData(String rowKey) {
        List<OrderItem> cars = (List<OrderItem>) getWrappedData();

        for(OrderItem car : cars) {
            if(car.getProduct().getId().compareTo(Long.parseLong(rowKey)) == 0)
                return car;
        }

        return null;
    }
}
